package br.com.sgdee.converter;

import java.math.BigDecimal;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

public class BigDecimalConverterCustom implements Converter {

	@Override
	public Object getAsObject(FacesContext context, UIComponent component, String value) {
		
		if (value != null) {
		
			String valor = String.valueOf(value);
			
			valor = valor.replace("R$", "");
			valor = valor.replaceAll("\\.", "");
			valor = valor.replace(",", ".");
			
			return new BigDecimal(valor);
		}
		
		return "";
	}

	@Override
	public String getAsString(FacesContext context, UIComponent component, Object value) {
		
	   if (value != null && ! "".equals(value)) {
 
            return String.valueOf(value);
        }
        return "";
	}

}
